#! /usr/bin/env bash
#
# Re-indent an OCaml file passed as argument. This is meant to be invoked
# by 'pre-commit' as part of a pre-commit hook.
#
set -eu

eval $(opam env)

if $(ocamlformat --version > /dev/null 2>&1); then
  ocamlformat --inplace --enable-outside-detected-project "$@"
else
  cat <<EOF
*** ocamlformat was not found. ***

If you wish to re-indent OCaml code, you must install ocamlformat, which is
normally done with the following command:

  $ opam install ocamlformat

For now, let's pretend everything is fine.
EOF
fi
